package com.test.practice.socket.url;

import lombok.Cleanup;

import javax.net.ssl.HttpsURLConnection;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * URL
 *
 * @Description: URL
 * =======================
 * @Author: Jovi
 * =======================
 * @Date: Created in 2023-02-10
 * =======================
 * @Version: 1.1.2.0
 */
public class UrlDemo {

    public static void main(String[] args) throws Exception {
//        m1();


        URL url = new URL("https://vod.tenghuiwangxiao.cn/16f15910vodcq1258158934/72a5b3f7243791577870802039/playlist.f9.mp4");

        HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();

        @Cleanup InputStream is = urlConnection.getInputStream();

        @Cleanup FileOutputStream fos = new FileOutputStream("1.mp4");

        byte[] datas = new byte[1024];

        int len;

        while ((len = is.read(datas)) != -1) {
            fos.write(datas, 0, len);
        }


    }


    private static void m1() throws MalformedURLException {
        URL url = new URL("https://case.yunchejinrong.com/anguan/case/caseManage/individualCase");
        System.out.println("getProtocol() :" + url.getProtocol());
        System.out.println("getHost() :" + url.getHost());
        System.out.println("getPort() :" + url.getPort());
        System.out.println("getPath() :" + url.getPath());
        System.out.println("getFile() :" + url.getFile());
        System.out.println("getQuery() :" + url.getQuery());
    }
}
